package com.gzm.springcloud.controller;

import com.gzm.springcloud.pojo.Dept;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @ClassName DeptController_consumer
 * @Description:
 * @Author gzm
 * @Date 2020/11/23 11:12
 **/
@RestController
@RequestMapping("/consumer")
@Api(description = "服务消费者")
public class DeptController_consumer {
    //这里需要跟注册中心application名字一致，区分大小写
    private static final String REST_URL_PREFIX = "http://WOOLCLOUD-DEPT";
    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/dept/add")
    public boolean add(@RequestBody Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
    }
    @GetMapping(value="/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id)
    {
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id, Dept.class);
    }

    @GetMapping(value="/dept/list")
    public List<Dept> list()
    {
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list", List.class);
    }

    @GetMapping("/discovery")
    public Object discovery(){
      return  restTemplate.getForObject(REST_URL_PREFIX+"/dept/discovery",Object.class);
    }
}
